﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.AuthorCenter.Tenants;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.DependencyInjection;
using Volo.Abp.TenantManagement;

namespace mozhi.smarterp.AuthorCenter.Controllers
{
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(TenantController) ,IncludeSelf =true)]
    public class CustomTenantController : TenantController
    {
        private ICustomTenantAppService _appService;

        public CustomTenantController(ICustomTenantAppService tenantAppService) : base(tenantAppService)
        {
            _appService = tenantAppService;
        }

        [HttpGet]
        [Route("{id}/connections")]
        [Authorize(TenantManagementPermissions.Tenants.ManageConnectionStrings)]
        public async Task<List<TenantConnectionDto>> GetConnectionStringAsync(Guid id)
        {
            return await _appService.GetConnectionAsync(new TenantConnectionFilter() { TenantId = id });
        }

        [HttpPut]
        [Route("{id}/connections")]
        [Authorize(TenantManagementPermissions.Tenants.ManageConnectionStrings)]
        public virtual Task UpdateConnectionStringAsync(Guid id, List<TenantConnectionUpdateDto> input)
        {
            return _appService.UpdateConnectionAsync(id, input);
        }

        [HttpDelete]
        [Route("{id}/connections")]
        [Authorize(TenantManagementPermissions.Tenants.ManageConnectionStrings)]
        public virtual Task DeleteConnectionStringAsync(Guid id , string connectionName)
        {
            return _appService.DeleteConnectionAsync(id , connectionName);
        }
    }
}
